// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using NSQL.Sharpen;

namespace NSQL.Expressions.Functions
{
    public class PercentileFunction : BaseExpression, IPercentileFunction
    {
        public AggregateType AggregateType => AggregateType.None;
        public INumericExpression Expr { get; set; }
        public PercentileType Type { get; set; }
        public INumericExpression P { get; set; }
        public Order Order { get; set; }

        public PercentileFunction(INumericExpression expression, INumericExpression p, PercentileType type, Order order)
        {
            Expr = expression;
            P = p;
            Type = type;
            Order = order;
        }

        public override bool IsValid => Expr != null && Expr.IsValid;
        
        protected override IExpression DeepCopy()
        {
            return new PercentileFunction(Expr.DeepClone(), P, Type, Order)
            {
                Tag = Tag
            };
        }
        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);

        public override void Accept(IExpressionVisitor visitor) => visitor.Visit(this);
    }
}